package org.example.top40;

import java.util.ArrayList;
import java.util.List;

public class main40_1 {
    //二叉树中序遍历
    //递归
    public static void main(String[] args) {
        TreeNode root = builder();
        List<Integer> res=new ArrayList<>();
        searchIn(root,res);
        System.out.println(res);
    }

    private static void searchIn(TreeNode root,List<Integer> res) {
        if(root==null){
            return ;
        }
        searchIn(root.left,res);
        res.add(root.val);
        searchIn(root.right,res);
    }

    private static TreeNode builder(){
        /**
         *       3
         *     9   20
         *        15  7
         */
        TreeNode root = new TreeNode(3);
        TreeNode node1 = new TreeNode(9);
        TreeNode node2 = new TreeNode(20);
        TreeNode node3 = new TreeNode(15);
        TreeNode node4 = new TreeNode(7);
        root.left=node1;
        root.right=node2;
        node2.left=node3;
        node2.right=node4;
        return root;
    }
}
